package client;

import java.net.ServerSocket;

import server.MyNapsterProtocol;

public class ClientTransferThread extends Thread {

	private ClientSocket clientSocket;
	private ServerSocket transferSocket;
	
	public ClientTransferThread(ClientSocket clientSocket) {
		this.clientSocket = clientSocket;
	}
	
	@Override
	public void run() {
		ClientTransferSocket clientTransferSocket;
		boolean listening = true;
		try {
			transferSocket = new ServerSocket(MyNapsterProtocol.CLIENT_PORT);
			while (listening) {
				clientTransferSocket = new ClientTransferSocket(clientSocket.getClientGui(), transferSocket.accept());
				clientTransferSocket.run();
			}
			close();
		}catch (Exception e) {
			clientSocket.getClientGui().appendLogMessage(e.getMessage());
		}
	}
	
	public void close() {
		try {
			transferSocket.close();
		}catch (Exception e) {
			clientSocket.getClientGui().appendLogMessage(e.getMessage());
		}
		
	}
}
